package codeTop;

public class q152 {
    public int maxProduct(int[] nums) {
        long res = Integer.MIN_VALUE;
        int max = 1;
        int min = 1;
        for (int i = 0; i < nums.length; i++) {
            int temp = Math.max(Math.max(nums[i]*max, nums[i]*min),nums[i]);
            min = Math.min(Math.min(nums[i]*min,nums[i]*max ),nums[i]);
            max = temp;
            res = Math.max(res,max);
        }
        return (int)res;
    }

    public static void main(String[] args) {
        q152 q = new q152();
        System.out.println(q.maxProduct(new int[]{-4, -3, -2}));
    }
}
